package cn.project.engineering.ui.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;

import java.util.ArrayList;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import cn.project.engineering.R;
import cn.project.engineering.http.bean.ThingInfo;
import cn.project.engineering.ui.adapter.DialogListDapter;
import cn.project.engineering.utils.DialogCallback;
import cn.project.engineering.utils.WonderfulScreenSize;


/**
 */
public class WonderfulDialog {


    /**
     * 自定义对话框
     */
    public static  Dialog sopDialog(Context context, String string) {
        final Dialog dialog = new Dialog(context, R.style.NormalDialogStyle);
        View view = View.inflate(context, R.layout.dialog_normal_sop, null);
        if (!string.equals("")){
            ((TextView)view.findViewById(R.id.dialog_content)).setText(string);
        }
        dialog.setContentView(view);
        //使得点击对话框外部不消失对话框  外面布局要全屏拦截
        dialog.setCanceledOnTouchOutside(false);
        //设置对话框的大小
        view.setMinimumHeight((int) (WonderfulScreenSize.getInstance(context).getScreenHight() * 0.23f));
        Window dialogWindow = dialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = (int) (WonderfulScreenSize.getInstance(context).getScreenWith() * 0.75f);//设置对话框的宽度
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;//设置对话框的高度
        lp.gravity = Gravity.CENTER;
        dialogWindow.setAttributes(lp);
        dialog.show();
        return dialog;
    }
    /**
     * 自定义对话框
     */
    public static  void passDialog(Context context, final DialogCallback dialogCallback, String string) {
        final Dialog dialog = new Dialog(context, R.style.NormalDialogStyle);
        View view = View.inflate(context, R.layout.dialog_normal, null);
        if (!string.equals("")){
//          string
        }
        EditText tv=((EditText)view.findViewById(R.id.dialog_content));
        TextView cancel = (TextView) view.findViewById(R.id.cancel);

        TextView confirm = (TextView) view.findViewById(R.id.confirm);
        dialog.setContentView(view);
        //使得点击对话框外部不消失对话框  外面布局要全屏拦截
        dialog.setCanceledOnTouchOutside(false);
        //设置对话框的大小
        view.setMinimumHeight((int) (WonderfulScreenSize.getInstance(context).getScreenHight() * 0.23f));
        Window dialogWindow = dialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = (int) (WonderfulScreenSize.getInstance(context).getScreenWith() * 0.75f);//设置对话框的宽度
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;//设置对话框的高度
        lp.gravity = Gravity.CENTER;
        dialogWindow.setAttributes(lp);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                dialogCallback.cancel();
            }
        });
        confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                dialogCallback.confirm(tv.getText().toString().trim());

            }
        });
        dialog.show();
    }
    /**
     * 自定义对话框
     */
    public static  void listDialog(Context context, final DialogCallback dialogCallback, ArrayList<ThingInfo> data) {
        final Dialog dialog = new Dialog(context, R.style.NormalDialogStyle);
        View view = View.inflate(context, R.layout.dialog_list, null);

        RecyclerView tv=((RecyclerView)view.findViewById(R.id.dialog_list));

        tv.setLayoutManager(new LinearLayoutManager(context));
        DialogListDapter dialogListDapter=new DialogListDapter(R.layout.item_menu,data);
        tv.setAdapter(dialogListDapter);
        dialogListDapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                dialogCallback.confirm(data.get(position).getPartNO());
                dialog.dismiss();
            }
        });
        dialog.setContentView(view);
        //使得点击对话框外部不消失对话框  外面布局要全屏拦截
        dialog.setCanceledOnTouchOutside(false);
        //设置对话框的大小
        view.setMinimumHeight((int) (WonderfulScreenSize.getInstance(context).getScreenHight() * 0.23f));
        Window dialogWindow = dialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = (int) (WonderfulScreenSize.getInstance(context).getScreenWith() * 0.75f);//设置对话框的宽度
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;//设置对话框的高度
        lp.gravity = Gravity.CENTER;
        dialogWindow.setAttributes(lp);
        dialog.show();
    }
    /**
     * 升级弹框
     */

    /**
     * 自定义单按钮对话框
     */
//    public static  void customDialogSingle(Context context, String title, String conttent) {
//        final Dialog dialog = new Dialog(context, R.style.NormalDialogStyle);
//        View view = View.inflate(context, R.layout.dialog_normal_single, null);
//        ((TextView)view.findViewById(R.id.single_title)).setText(title);
//        ((TextView)view.findViewById(R.id.single_content)).setText(conttent);
//        TextView confirm = (TextView) view.findViewById(R.id.single_confirm);
//        dialog.setContentView(view);
//        //        //使得点击对话框外部不消失对话框  外面布局要全屏拦截
//
//        dialog.setCanceledOnTouchOutside(false);
//        //设置对话框的大小
//        view.setMinimumHeight((int) (WonderfulScreenSize.getInstance(context).getScreenHeight() * 0.23f));
//        Window dialogWindow = dialog.getWindow();
////        dialogWindow.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
//        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
//        lp.width = (int) (WonderfulScreenSize.getInstance(context).getScreenWidth() * 0.75f);//设置对话框的宽度
//        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;//设置对话框的高度
//        lp.gravity = Gravity.CENTER;
//        dialogWindow.setAttributes(lp);
//        confirm.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                dialog.dismiss();
//
//            }
//        });
//        dialog.show();
//    }
    /**
     * 自定义单按钮对话框
     */
//    public static  void customDialogSingle(Context context, String title, String conttent, final DialogCallback dialogCallback) {
//        final Dialog dialog = new Dialog(context, R.style.NormalDialogStyle);
//        View view = View.inflate(context, R.layout.dialog_normal_single, null);
//        ((TextView)view.findViewById(R.id.single_title)).setText(title);
//        ((TextView)view.findViewById(R.id.single_content)).setText(conttent);
//        TextView confirm = (TextView) view.findViewById(R.id.single_confirm);
//        dialog.setContentView(view);
//        //        //使得点击对话框外部不消失对话框  外面布局要全屏拦截
//
//        dialog.setCanceledOnTouchOutside(false);
//        //设置对话框的大小
//        view.setMinimumHeight((int) (WonderfulScreenSize.getInstance(context).getScreenHeight() * 0.23f));
//        Window dialogWindow = dialog.getWindow();
//        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
//        lp.width = (int) (WonderfulScreenSize.getInstance(context).getScreenWidth() * 0.75f);//设置对话框的宽度
//        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;//设置对话框的高度
//        lp.gravity = Gravity.CENTER;
//        dialogWindow.setAttributes(lp);
//        confirm.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                dialogCallback.cance();
//                dialog.dismiss();
//            }
//        });
//        dialog.show();
//    }
    /**
     * 自定义底部对话框
     */
//    public static void customBottomDialog(Context context, final BottemDialogCallback bottemDialogCallback) {
//        /**
//         *
//         */
//        final Dialog dialog = new Dialog(context, R.style.NormalDialogStyle);
//        View view = View.inflate(context, R.layout.dialog_bottom, null);
//        view.findViewById(R.id.photo_select).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                bottemDialogCallback.selectPostion(2);
//                dialog.dismiss();
//            }
//        });
//        view.findViewById(R.id.gall_select).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                bottemDialogCallback.selectPostion(1);
//                dialog.dismiss();
//            }
//        });
//        view.findViewById(R.id.cancel_select).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                dialog.dismiss();
//            }
//        });
//        dialog.setContentView(view);
//        dialog.setCanceledOnTouchOutside(true);
//        view.setMinimumHeight((int) (WonderfulScreenSize.getInstance(context).getScreenHeight() * 0.23f));
//        Window dialogWindow = dialog.getWindow();
//        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
//        lp.width = (int) (WonderfulScreenSize.getInstance(context).getScreenWidth() * 0.9f);
//        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
//        lp.gravity = Gravity.BOTTOM;
//        dialogWindow.setAttributes(lp);
//        dialog.show();
//    }
//    /**
//     * 自定义单按钮对话框
//     */
//    public static  void upDialoge(Context context) {
//        final Dialog dialog = new Dialog(context, R.style.NormalDialogStyle);
//        View view = View.inflate(context, R.layout.dialog_lock, null);
//        dialog.setContentView(view);
//        //使得点击对话框外部不消失对话框  外面布局要全屏拦截
//        dialog.setCanceledOnTouchOutside(false);
//        //设置对话框的大小
//        view.setMinimumHeight((int) (WonderfulScreenSize.getInstance(context).getScreenHeight() * 0.23f));
//        Window dialogWindow = dialog.getWindow();
//        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
//        lp.width = (int) (WonderfulScreenSize.getInstance(context).getScreenWidth() * 0.75f);//设置对话框的宽度
//        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;//设置对话框的高度
//        lp.gravity = Gravity.CENTER;
//        dialogWindow.setAttributes(lp);
//        dialog.show();
//    }
}
